package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.PermissionDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionDao permissionDao ;


    //分页查询
    @Override
    public PageResult findAll(QueryPageBean queryPageBean) {

        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();

        PageHelper.startPage(currentPage , pageSize);

        Page<Permission> page = permissionDao.findAll(queryString);

        return new PageResult(page.getTotal() ,page.getResult());
    }
    //新增
    @Override
    public void add(Permission permission) {
        permissionDao.add(permission);
    }
    //编辑
    @Override
    public void edit(Permission permission) {
        permissionDao.edit(permission);
    }
    //用户回显
    @Override
    public Permission findByIdWithPermission(Integer id) {
        return permissionDao.findByIdWithPermission(id);
    }
    //删除
    @Override
    public void delete(Integer id) {
        permissionDao.delete(id);
    }
}
